/**
 * 主页View视图
 */
define(['text!module/index/templates/IndexView.html'], function(indexTemplate) {  	
	return ngc.View.extend({
		el:"#main_index_content",
		template : ngc.compile(indexTemplate),	
		events : {
		},
		afterRender:function(){
			var that = this;
			ngc.progress();
			this.requireView({selector:"#nav_content",url:'module/index/views/NavView'}).then(function(){				
				that.init_content();
			});
							
		},
		//获取URL中的参数
		getQueryString:function(name) {
		    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
		    var r = window.location.search.substr(1).match(reg);
		    if (r != null) {
		        return unescape(r[2]);
		    }
		    return null;
		},
		
		init_content:function(){
			var that = this;
			global = new Object();
			global.enumData = new Object();
			
			//通过URL判断用户是否具备操作功能
			global.edit = false;
			var value = this.getQueryString("key");
			if(value){
				var secret = ngc.callServerFunction("com.ztesoft.hostapp.inf.CommonInf","checkKeySecret", value);
				if(secret.responseJSON.data == true){
					global.edit = true;
				}
			}
			
			that.resizeMainContent();
			this.requireView({selector:"#mainContent",url:'module/component/views/TabView',viewOption:{config:{labelSize:12,oneIsHidden:true}}}).then(function(){
				//that.resizeMainContent();
				/**
				 * 打开主页Tab页，通过ngc.trigger("creatIndexTabView",tabId, label, taburl, active, closed, params)进行触发
				 */
				var tab_view = that.getView("#mainContent");
				
				ngc.on("creatIndexTabView",function(tabId, label, taburl, active, closed, params){
					tab_view.openView(tabId, label, taburl, active, closed, params);
				});
				ngc.on("removeThisTab",function(tabId){
					tab_view.removeTab(tabId);
				});
				ngc.progress();
				
				// 开发测试使用
				tab_view.openView('sysManager',
						'系统设置', 'module/systemconfig/views/systemConfigView',true, false,{callback:function(){
						}});
                tab_view.openView('datasourceManager',
                    '数据源管理', 'module/systemconfig/views/systemConfigView',true, false,{callback:function(){
                    }});
				// tab_view.openView('appManager',
				// 		'应用管理', 'module/hostapp/views/AppView',true, false,{callback:function(){
				// 		}});

				ngc.on("domainChange",function(){
					var tabs = tab_view.getAllTabs();
					$.each(tabs,function(i){
						if(i!=0)
							tab_view.removeTab(i);
					});
					that.getView("#tree_content").refresh();
				});
			});	
		},
		
		resizeMainContent:function(){
			 var $main = this.$('#mainContent');
			 $main.css("overflow-y", 'auto');
			 $main.css("overflow-x", 'hidden');
	         var height = $main.parent().parent().innerHeight() - $main.parent().parent().children('#nav_content').outerHeight(true);
	         $main.outerHeight(height);	
	         
	         var tree_view = this.getView("#tree_content");
	         if(tree_view&&tree_view._getTree&&tree_view._getTree()&&tree_view._getTree().getInitFlag&&tree_view._getTree().getInitFlag()==true){
	        	 tree_view._getTree().setHeight(height-78);
	         }else{
	        	 if(tree_view&&tree_view.on){
	        		 tree_view.on("viewRenderAfter",function(){
	        			 this._getTree().setHeight(height-78);
		        	 });
	        	 }
	        	 
	         }
	         
		}
		
	});
		
});  

